package org.algorithm.string;
/**
 * 两个整数字符串相加，要求不能转换为整数，返回值还是字符串
 *
 * 思路：
 * 1、如果两个字符串长度不同，那么长度小的用0来补齐高位
 * 2、用%10来放当前位，/10来补齐上一位
 */
public class TowIntStrAdd {
    private static String addStrings(String num1, String num2) {
        StringBuilder result = new StringBuilder();
        int carry =0;
        int i = num1.length()-1;
        int j = num2.length()-1;
        while (i>=0 || j>=0 || carry!=0){
            int digit1=(i>=0)?num1.charAt(i)-'0':0;
            int digit2=(i>=0)?num2.charAt(i)-'0':0;
            int sum = digit1 + digit2 + carry;
            result.insert(0,sum%10);
            carry=sum/10;
            i--;
            j--;
        }
        return result.toString();
    }

    public static void main(String[] args) {
        System.out.println(addStrings("1234","8766"));
    }
}
